<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
    <script src="./js/vue.js"></script>
    <style>
        li a {
            text-decoration: none;
            color: red;
        }
        .list-enter,
        .list-leave-to {
            opacity: 0;
            transform: translateY(70px);
        }

        .list-enter-to,
        .list-leave {
            opacity: 1;
        }

        .list-enter-active,
        .list-leave-active {
            transition: all 1s;
        }
    </style>
</head>

<body>
    <div id="app">
        <form action="#">
            <input type="text" placeholder="请输入内容" v-model="msg">
            <input type="submit" value="添加" @click="add" name="" id="">
        </form>
        <transition-group tag="ul" name="list">
            <todolist v-for="(item, index) in list" :key="index" :content="item" :index="index" @delete="del"></todolist>
        </transition-group>
    </div>
    <script>
        Vue.component('todolist', {
            props: ['content', 'index'],
            template: '<li>{{content}} <a @click=dj>x</a> </li>',
            methods: {
                dj: function () {
                    this.$emit('delete', this.index)
                }
            }
        })
        let vm = new Vue({
            el: "#app",
            data: {
                list: ["苏玮一真美", "苏玮一真漂亮"],
                msg: ''
            },
            methods: {
                del(index) {
                    this.list.splice(index, 1)
                },
                add() {
                    this.list.push(this.msg),
                        this.msg = ''
                }
            }
        })
    </script>
</body>

<html>